/**
 * Project Name:HomeActivity
 * Date:2016-7-4下午12:03:31
 * Copyright (c) 2016, askzhao All Rights Reserved.
 *
 */
package com.kkd.kkdapp.view;

import com.kkd.kkdapp.R;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.RelativeLayout;

/**
 * ClassName: HomeQuickEntryView <br/>
 * date: 2016-7-4 下午12:03:31 <br/>
 * 
 * @author askzhao
 * @version
 */
public class HomeQuickEntryView extends RelativeLayout {

	private Context mContext;
	public RecyclerView mQuickEntryGrid;

	/**
	 * @param context
	 */
	public HomeQuickEntryView(Context context) {
		super(context);
		init(context);
	}

	/**
	 * @param context
	 * @param attrs
	 */
	public HomeQuickEntryView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);

	}

	/**
	 * @param context
	 * @param attrs
	 * @param defStyle
	 */
	public HomeQuickEntryView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	/**
	 * init:(初始化操作). <br/>
	 * 
	 * @author askzhao
	 */
	private void init(Context context) {

		mContext = context;
		View mContentView = RelativeLayout.inflate(mContext,
				R.layout.home_quick_entry, null);
		android.view.ViewGroup.LayoutParams params = new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		addView(mContentView, params);

		mQuickEntryGrid = (RecyclerView) mContentView
				.findViewById(R.id.quick_entry_grid);
		mQuickEntryGrid.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.HORIZONTAL));
		mQuickEntryGrid.setItemAnimator(new MyItemAnimator());

	}

	public void setAdapter(Adapter adapter) {
		mQuickEntryGrid.setAdapter(adapter);
	}

	class MyItemAnimator extends DefaultItemAnimator{
		
		@Override
		public boolean animateChange(ViewHolder oldHolder,
				ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
			return super.animateChange(oldHolder, newHolder, fromX, fromY, toX, toY);
		}
	}
}
